<%@page import="search.transcoord.TransCoordLoader"%>
<%@page import="search.local.LocalItem"%>
<%@page import="java.util.ArrayList"%>
<%@page import="search.local.LocalLoader"%>
<%@page import="java.util.Calendar"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%
	String start = request.getParameter("start");
	String end = request.getParameter("end");
	String time = request.getParameter("time");
	String start_location = request.getParameter("start_location");
	String end_location = request.getParameter("end_location");

	if (start == null || start.equals("")) {
		start_location = new String(start_location.getBytes("ISO-8859-1"), "UTF-8");
		LocalLoader loader = new LocalLoader();
		ArrayList<LocalItem> list = loader.getLocalList(start_location);
		if (list != null) {
			if (!start_location.equals("")) {
				if (list.size() < 1) {
					out.print("<script type='text/javascript'>alert('검색된 출발지 정보가 없습니다.');history.back();</script>");
				} else {
					LocalItem item = list.get(0);
					TransCoordLoader tloader = new TransCoordLoader();
					start = tloader.getTransCoord(item.getMapx(), item.getMapy());
				}
			}
		}
	}
	
	if (end == null || end.equals("")) {
		end_location = new String(end_location.getBytes("ISO-8859-1"), "UTF-8");
		LocalLoader loader = new LocalLoader();
		ArrayList<LocalItem> list = loader.getLocalList(end_location);
		if (list != null) {
			if (!end_location.equals("")) {
				if (list.size() < 1) {
					out.print("<script type='text/javascript'>alert('검색된 도착지 정보가 없습니다.');history.back();</script>");
				} else {
					LocalItem item = list.get(0);
					TransCoordLoader tloader = new TransCoordLoader();
					end = tloader.getTransCoord(item.getMapx(), item.getMapy());
				}
			}
		}
	}
	
	if (start == null || start.equals("")) {
		out.print("<script>alert('출발지 입력이 필요합니다.');location.replace('index.jsp');</script>");
	}
	
	if (end == null || end.equals("")) {
		out.print("<script>alert('도착지 입력이 필요합니다.');location.replace('index.jsp');</script>");
	}
	
	if (time == null || time.equals("")) {
		Calendar cal = Calendar.getInstance();
		time = cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE);
	}
	
	int hh = Integer.parseInt(time.substring(0, 2));
	int mm = Integer.parseInt(time.substring(3, 5));
	
	if (start != null && !start.equals("") && end != null && !end.equals("")) {
		start = new String(start.getBytes("ISO-8859-1"), "UTF-8");
		end = new String(end.getBytes("ISO-8859-1"), "UTF-8");
	}
%>
<!DOCTYPE html>
<html>
<head>
<meta charset=UTF-8 />
<meta name=viewport content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" />
<meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1" />
<link rel="shortcut icon" href=assets/ico/favicon.png />
<link rel=apple-touch-icon-precomposed href=assets/ico/apple-touch-icon-57-precomposed.png />
<link rel=apple-touch-icon-precomposed sizes=72x72 href=assets/ico/apple-touch-icon-72-precomposed.png />
<link rel=apple-touch-icon-precomposed sizes=114x114 href=assets/ico/apple-touch-icon-114-precomposed.png />
<link rel=apple-touch-icon-precomposed sizes=144x144 href=assets/ico/apple-touch-icon-144-precomposed.png />
<link rel=stylesheet type=text/css href=assets/css/bootstrap.min.css />
<link rel=stylesheet type=text/css href=assets/css/nanumfont.css />
<link rel=stylesheet type=text/css href=assets/font-awesome-4.0.3/css/font-awesome.min.css />
<!--[if lt IE 9]>
<script type=text/javascript src=assets/js/html5shiv.js></script>
<script type=text/javascript src=assets/js/respond.min.js></script>
<![endif]-->
<!--[if gt IE 9]>
<link rel=stylesheet type=text/css href=assets/css/ie10.css />
<script type=text/javascript src=assets/js/ie10.js></script>
<![endif]-->
<title>경로검색 결과</title>
<link rel=stylesheet href=assets/css/select_result.css>
</head>
<body onload=calcRoute()>
<input type=hidden id=start value=<%=start%>>
<input type=hidden id=end value=<%=end%>>
<input type=hidden id=hh value=<%=hh%>>
<input type=hidden id=mm value=<%=mm%>>
<nav class="navbar navbar-fixed-top" role=navigation>
<div class="nav_content text-center">
<div class="nav_menu_btn pull-left text-center">
<a class=back_btn onclick=history.back()><i class="fa fa-arrow-left"></i></a>
</div>
<span class=page_title><strong>경로선택</strong></span>
</div>
</nav>
<div id=test class=panel-group>
</div>
<script src=assets/js/jquery.js></script>
<script src=assets/js/bootstrap.min.js></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script src=assets/js/googlemap.js></script>
</body>
</html>